<template>
	<view>
		<view class="header">
			<view class="bg">
				<view class="box">
					<view class="box-hd">
						<view class="avator" @click="toPage('/pages/user/info/info')"><image :src="userInfo.headPic"></image></view>
						<view class="phone-number">{{userInfo.phone}}</view>
					</view>
					<view class="box-bd">
						<view class="item" >
							<view class="icon"><image src="/static/img/user/message.png" ></image></view>
							<view class="text">我的通知</view>
						</view>
						<view class="item">
							<view class="icon"><image src="/static/img/user/set.png" ></image></view>
							<view class="text">我的通知</view>
						</view>
						<view class="item">
							<view class="icon"><image src="/static/img/user/help.png" ></image></view>
							<view class="text">我的通知</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="list-content">
			<view class="list">
				<view class="li noborder" @click="toPage('/pages/user/info/info')">
					<view class="icon"><image src="/static/img/user/user.png"></image></view>
					<view class="text">个人中心</view>
					<image class="to" src="/static/img/user/right-arrow.png"></image>
				</view>
			</view>
			<view class="list">
				<view class="li" @click="toPage('/pages/user/help/help')">
					<view class="icon"><image src="/static/img/user/help.png"></image></view>
					<view class="text">帮助中心</view>
					<image class="to" src="/static/img/user/right-arrow.png"></image>
				</view>
				<view class="li" @click="toPage('/pages/user/about/about')">
					<view class="icon"><image src="/static/img/user/about.png"></image></view>
					<view class="text">关于我们</view>
					<image class="to" src="/static/img/user/right-arrow.png"></image>
				</view>
				<view class="li" @click="toPage('/pages/user/feedback/feedback')">
					<view class="icon"><image src="/static/img/user/feedback.png"></image></view>
					<view class="text">意见反馈</view>
					<image class="to" src="/static/img/user/right-arrow.png"></image>
				</view>
			</view>
			<view class="list">
				<view class="li noborder">
					<view class="icon"><image src="/static/img/user/set.png"></image></view>
					<view class="text">系统设置</view>
					<image class="to" src="/static/img/user/right-arrow.png"></image>
				</view>
			</view>
		</view>
		<button class="logout-btn" type="primary" @click="onLogout">退出登录</button>
	</view>
</template>
<script>
import loginService from '../../../api/login.js';
export default {
	data() {
		return {
			userInfo:{}
		};
	},
	onLoad() {
		const that = this
		that.userInfo = uni.getStorageSync(that.$config.USER_KEY)
	},
	methods: {
		//跳转到某一个页面
		toPage: function(page) {
			uni.navigateTo({
				url: page
			});
		},
		//退出登录
		onLogout: function() {
			const that = this;
			uni.showModal({
				title: '温馨提示',
				confirmText: '确认',
				cancelText: '取消',
				content: '您确认要退出登录吗？点击确定退出应用。',
				success: function(res) {
					if (res.confirm) {
						loginService.logout().then(res => {
							//登出成功，删除相应的存储
							if (res && res.success) {
								//清理所有本地缓存的东西
								try {
									uni.removeStorageSync(that.$config.TOKEN_NAME);
									uni.removeStorageSync(that.$config.USER_KEY);
								} catch (e) {
									console.info('清理缓存错误', e);
								}
								//等待一下先，到登录页面
								setTimeout(function() {
									//退出成功后，直接回到登录页面
									uni.reLaunch({
										url: '/pages/login/login'
									});
								}, 50);
							}
						});
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f1f1f1;
	font-size: 30rpx;
}
.header {
	background: #fff;
	height: 290rpx;
	padding-bottom: 110rpx;
	.bg {
		width: 100%;
		height: 200rpx;
		padding-top: 100rpx;
		background-color: #007aff;
	}
}
.box {
	width: 650rpx;
	height: 280rpx;
	border-radius: 20rpx;
	margin: 0 auto;
	background: #fff;
	box-shadow: 0 5rpx 20rpx 0rpx rgba(0, 0, 150, 0.2);
	.box-hd {
		display: flex;
		flex-wrap: wrap;
		flex-direction: row;
		justify-content: center;
		.avator {
			width: 160rpx;
			height: 160rpx;
			background: #fff;
			border: 5rpx solid #fff;
			border-radius: 50%;
			margin-top: -80rpx;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.phone-number {
			width: 100%;
			text-align: center;
		}
	}
	.box-bd {
		display: flex;
		flex-wrap: nowrap;
		flex-direction: row;
		justify-content: center;
		.item {
			flex: 1 1 auto;
			display: flex;
			flex-wrap: wrap;
			flex-direction: row;
			justify-content: center;
			border-right: 1px solid #f1f1f1;
			margin: 15rpx 0;
			&:last-child {
				border: none;
			}
			.icon {
				width: 60rpx;
				height: 60rpx;
				image {
					width: 50rpx;
					height: 50rpx;
				}
			}
			.text {
				width: 100%;
				text-align: center;
				margin-top: 10rpx;
			}
		}
	}
}
.list-content {
	background: #fff;
}
.list {
	width: 100%;
	border-bottom: 15rpx solid #f1f1f1;
	background: #fff;
	&:last-child {
		border: none;
	}
	.li {
		width: 92%;
		height: 100rpx;
		padding: 0 4%;
		border-bottom: 1px solid rgb(243, 243, 243);
		display: flex;
		align-items: center;
		&.noborder {
			border-bottom: 0;
		}
		.icon {
			flex-shrink: 0;
			width: 50rpx;
			height: 50rpx;
			image {
				width: 50rpx;
				height: 50rpx;
			}
		}
		.text {
			padding-left: 20rpx;
			width: 100%;
			color: #666;
		}
		.to {
			flex-shrink: 0;
			width: 40rpx;
			height: 40rpx;
		}
	}
}

.logout-btn {
	color: #f4f5f6;
	height: 90rpx;
	line-height: 90rpx;
	box-sizing: border-box;
	border: 2rpx solid #e5e5e5;
	border-radius: 50rpx;
	font-family: inherit;
	background: $uni-color-primary;
	resize: none;
	margin: 30rpx;
}
</style>
